package com.tianhui.consignortwofei.other.auth.recognition.process;

import android.text.TextUtils;

import com.baidu.ocr.sdk.model.IDCardResult;
import com.fgs.common.utils.ToastUtil;
import com.tianhui.consignortwofei.mvp.model.enty.RecognitionInfo;
import com.tianhui.consignortwofei.mvp.model.enty.SelectPhotoInfo;
import com.tianhui.consignortwofei.mvp.model.enty.authLicense.IdCardInfo;
import com.tianhui.consignortwofei.other.auth.inte.ProcessCallback;
import com.tianhui.consignortwofei.other.auth.recognition.recognitionResultProcess.IdCardOcrResultProcess;

/**
 * @author fgs
 * @date 2021/5/13
 * @description
 **/
public class IdCardBackRecognitionProcess implements IRecognitionProcess<IDCardResult, IdCardInfo> {

    @Override
    public void recognitionProcess(RecognitionInfo<IDCardResult> recognitionInfo, SelectPhotoInfo selectPhotoInfo, ProcessCallback<IdCardInfo> processCallback) {
        IDCardResult idCardResult = recognitionInfo.info;
        String errorMessage = "不是身份证国徽页或图片太模糊，请重新上传";
        if (idCardResult != null) {
            IdCardOcrResultProcess idCardOcrResultProcess = new IdCardOcrResultProcess();
            IdCardInfo idCardInfo = idCardOcrResultProcess.getIdCardOcrResult(idCardResult);
            idCardInfo.path = selectPhotoInfo.filePath;

            if (TextUtils.isEmpty(idCardInfo.idcardendtime)) {
                ToastUtil.showShortToast(errorMessage);
                processCallback.processFailed();
            } else {
                processCallback.processSuccess(idCardInfo);
            }

        } else {
            ToastUtil.showShortToast(errorMessage);
            processCallback.processFailed();
        }

    }

}
